#!/bin/bash

echo "$@"

TMPDIR=`mktemp -d`
TARNAME="submitted-`date +%Y%m%d%H%M`.tar.gz"

(echo -e "\033[032mSubmitting Project\033[0m")

(echo -e "\033[032mCreating Tarball $TARNAME\033[0m")
cp -r $2 $TMPDIR
BASE=`basename $2`
rm -rf $TMPDIR/$BASE/lin
echo $BASE

cd $TMPDIR
tar czfh $TARNAME $BASE
cd -

mv $TMPDIR/$TARNAME .
rm -rf $TMPDIR

(echo -e "\033[032mUploading Tarball $TARNAME\033[0m")
rsync -avz $TARNAME $1:submit

if [ $? -eq 0 ]
then
(echo -e "\033[032mSubmission Complete.\033[0m")
(echo -e "\033[031mPlease, manually check that $TARNAME contains all relevant information for submission, and resubmit if necessary. Thank you.\033[0m")
else
(echo -e "\033[031mERROR! $TARNAME was NOT successfully uploaded. Please, rectify the problem and resubmit. Thank you.\033[0m")
fi
